package com.ruoyi.web.controller.emergency;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.emergency.domain.EmergencyExample;
import com.ruoyi.emergency.service.IEmergencyExampleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 经典案例Controller
 * 
 * @author ruoyi
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/control/emergencyExample")
public class EmergencyExampleController extends BaseController
{
    @Autowired
    private IEmergencyExampleService emergencyExampleService;

    /**
     * 查询经典案例列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyExample:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmergencyExample emergencyExample)
    {
        startPage();
        List<EmergencyExample> list = emergencyExampleService.selectEmergencyExampleList(emergencyExample);
        return getDataTable(list);
    }

    /**
     * 导出经典案例列表
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyExample:export')")
    @Log(title = "经典案例", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmergencyExample emergencyExample)
    {
        List<EmergencyExample> list = emergencyExampleService.selectEmergencyExampleList(emergencyExample);
        ExcelUtil<EmergencyExample> util = new ExcelUtil<EmergencyExample>(EmergencyExample.class);
        util.exportExcel(response, list, "经典案例数据");
    }

    /**
     * 获取经典案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyExample:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emergencyExampleService.selectEmergencyExampleById(id));
    }

    /**
     * 新增经典案例
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyExample:add')")
    @Log(title = "经典案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmergencyExample emergencyExample)
    {
        return toAjax(emergencyExampleService.insertEmergencyExample(emergencyExample));
    }

    /**
     * 修改经典案例
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyExample:edit')")
    @Log(title = "经典案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmergencyExample emergencyExample)
    {
        return toAjax(emergencyExampleService.updateEmergencyExample(emergencyExample));
    }

    /**
     * 删除经典案例
     */
    @PreAuthorize("@ss.hasPermi('control:emergencyExample:remove')")
    @Log(title = "经典案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emergencyExampleService.deleteEmergencyExampleByIds(ids));
    }
}
